package com.wyp168.renrenfilm.core.service.impl;

import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.wyp168.renrenfilm.core.dao.PlayDao;
import com.wyp168.renrenfilm.core.entity.PlayEntity;
import com.wyp168.renrenfilm.core.service.PlayService;


@Service("playService")
public class PlayServiceImpl extends ServiceImpl<PlayDao, PlayEntity> implements PlayService {

    @Override
    public PageInfo<PlayEntity> queryPage(Map<String, Object> params) {
        QueryWrapper<PlayEntity> queryWrapper = new QueryWrapper<>();
        String homeTitle = (String) params.get("key");
        if (!StringUtils.isEmpty(homeTitle)) {
            queryWrapper.like("title", homeTitle);
        }
        int page;
        int size;
        if (!Objects.isNull(params.get("page"))) {
            page = Integer.parseInt((String) params.get("page"));
        } else {
            page = 1;
        }

        if (!Objects.isNull(params.get("limit"))) {
            size = Integer.parseInt((String) params.get("limit"));
        } else {
            size = 100;
        }

        PageMethod.startPage(page, size);
        List<PlayEntity> playEntities = baseMapper.selectList(queryWrapper);

//        IPage<PlayEntity> page = this.page(
//                new Query<PlayEntity>().getPage(params),
//                new QueryWrapper<PlayEntity>()
//        );

        return new PageInfo<PlayEntity>(playEntities);
    }

}